﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Model;
using BusinnessLogic;
using DataLayer;

namespace scrumbench
{
    public partial class TasksDetailsForm : Form
    {
        private int taskid;

        public int Taskid
        {
            get { return taskid; }
            set { taskid = value; }
        }

        public TasksDetailsForm()
        {
            InitializeComponent();
        }

        public TasksDetailsForm(int taskid)
        {
            InitializeComponent();
            this.Taskid = taskid;
            
        }

        private void TasksDetailsForm_Load(object sender, EventArgs e)
        {
            cBoxStatus.Items.Add("Not Started");
            cBoxStatus.Items.Add("Started");
            cBoxStatus.Items.Add("Done");
            List<Tasks> FillBoxes = new List<Tasks>();
            TaskDetailHandle handle = new TaskDetailHandle();
            FillBoxes = handle.TaskDetail(taskid);

            foreach (Tasks TaskDetail in FillBoxes)
            {
                txtTask.Text = TaskDetail.Titel;
                txtUser.Text = TaskDetail.Username;
                txtProduct.Text = TaskDetail.Productname;
                txtSprint.Text = TaskDetail.Sprinttitel;
                txtUserStory.Text = TaskDetail.Userstorytitel;
                cBoxStatus.Text = TaskDetail.Status;
                txtEstWorkload.Text = TaskDetail.Estimatedworkload.ToString();
                txtRealWorkload.Text = TaskDetail.RealWorkload.ToString();

                txtAddComment.Text = TaskDetail.Comment;
                
                ListViewItem tempItem = new ListViewItem();
                tempItem.Text = TaskDetail.Impedimenttitel;
                tempItem.Tag = TaskDetail.ImpedimentID;
                lViewImp.Items.Add(tempItem);

            }
        }

        private void Add_ImPediment_click(object sender, EventArgs e)
        {
            string ITitel = addimpboxtitel.Text;
            string IDescrip = addimpboxdescrip.Text;
            int taskIndent = this.taskid;

            ImpedimentsManage AddImp = new ImpedimentsManage();
            AddImp.InsertImp(ITitel, IDescrip , taskIndent);

           MessageBox.Show("Impediment Added");
        }

        private void OpenImpDetail(object sender, MouseEventArgs e)
        {
            if (lViewImp.SelectedItems != null)
            {
                int impIDke = (int)lViewImp.FocusedItem.Tag;
    
                        ImpedimentDetailsForm nImpedimentsDetail = new ImpedimentDetailsForm(impIDke);
                        nImpedimentsDetail.Show();
             

            }
        }

        private void Addcomment_click(object sender, EventArgs e)
        {
            string comment = txtAddComment.Text;
            int taskindent = this.taskid;

            TaskDetailHandle AddTaskComment = new TaskDetailHandle();
            AddTaskComment.inserttask(taskindent, comment);
        }

        private void updateWorkloadStatus(object sender, EventArgs e)
        {
            string status = cBoxStatus.Text;
            int rworkload = int.Parse(txtRealWorkload.Text);
            int taskindent = this.taskid;

            TaskDetailHandle AddStatusRworkload = new TaskDetailHandle();
            AddStatusRworkload.tempsavestatusworkload(taskindent, status, rworkload, Convert.ToInt32(txtEstWorkload));

            MessageBox.Show("Realworkload and statusupdated");

        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
